package com.dyh.quickdemo.leqeeDb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/*
@Author=Joey Wheeler
@Date=2020/10/16 11:30
*/
@SpringBootTest
@Slf4j
public class OmsXXLFair {

    public static String url = "https://databasehub.leqee.com/api/QuickQueryController/syncExecute";
    public static int dbId = 36;//内贸bi库

    @Autowired
    RestTemplate restTemplate;

    @Test
    public void test() throws InterruptedException {
        while (true){
            OmsXXLFair omsPost = new OmsXXLFair();
            Req req = new Req();
            req.setDatabase_id(dbId);
                req.setSql("select gt.* from fairjob.group_task gt join fairjob.group g on g.group_id = gt.group_id\n" +
                        "where g.group_name in (\"同步聚石塔订单\",\"同步聚石塔退款\",\"同步原始订单\",\"订单推送WMS仓\",\n" +
                        "\"订单推送CAINIAO仓\",\n" +
                        "\"订单推送JL仓\",\n" +
                        "\"订单推送4PX仓\",\n" +
                        "\"订单推送ELC_SF仓\",\n" +
                        "\"订单推送BEST仓\",\n" +
                        "\"订单推送OTHER仓\"\n" +
                        ") and task_status in ('RETRY','ERROR') and gt.create_time >'2020-10:31'".trim());
            req.setToken("3547e22149241a73678cf4863118e8845f9d5a6419284");
            //String raw = restTemplate.postForObject(url,req,String.class);
            Rsp rsp = restTemplate.postForObject(url,req,Rsp.class);
            //log.info("res={}", JSON.toJSONString(rsp));
            if (!CollectionUtils.isEmpty(rsp.getData().getData())){
                log.error("警告 rsp={}",JSON.toJSONString(rsp));
            }
            log.info("safe");
            Thread.sleep(30*1000);
        }


    }

    /**
     * database_id : 36
     * sql : select * from fairjob.group order by group_id desc limit 500
     * token : b6cba3e6d69948981ef9075d21ed48e35f89069e44c8b
     */
    @Setter@Getter
    static class Req{
        private int database_id;
        private String sql;
        private String token;
    }

    @Setter@Getter
    static class Rsp{
        private String code;
        private Data data;
        @Setter@Getter
        static class Data{
            private List<JSONObject> data ;
        }

    }






}
